package com.ruoyi.project.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.HeEventBasicUndesirable;
import com.ruoyi.project.service.IHeEventBasicUndesirableService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 药物不良事件药品Controller
 * 
 * @author ruoyi
 * @date 2024-08-19
 */
@RestController
@RequestMapping("/undesirable")
public class HeEventBasicUndesirableController extends BaseController
{
    @Autowired
    private IHeEventBasicUndesirableService heEventBasicUndesirableService;

    /**
     * 查询药物不良事件药品列表
     */
    @RequiresPermissions("project:undesirable:list")
    @GetMapping("/list")
    public TableDataInfo list(HeEventBasicUndesirable heEventBasicUndesirable)
    {
        startPage();
        List<HeEventBasicUndesirable> list = heEventBasicUndesirableService.selectHeEventBasicUndesirableList(heEventBasicUndesirable);
        return getDataTable(list);
    }

    /**
     * 导出药物不良事件药品列表
     */
    @RequiresPermissions("project:undesirable:export")
    @Log(title = "药物不良事件药品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HeEventBasicUndesirable heEventBasicUndesirable)
    {
        List<HeEventBasicUndesirable> list = heEventBasicUndesirableService.selectHeEventBasicUndesirableList(heEventBasicUndesirable);
        ExcelUtil<HeEventBasicUndesirable> util = new ExcelUtil<HeEventBasicUndesirable>(HeEventBasicUndesirable.class);
        util.exportExcel(response, list, "药物不良事件药品数据");
    }

    /**
     * 获取药物不良事件药品详细信息
     */
    @RequiresPermissions("project:undesirable:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(heEventBasicUndesirableService.selectHeEventBasicUndesirableById(id));
    }

    /**
     * 新增药物不良事件药品
     */
    @RequiresPermissions("project:undesirable:add")
    @Log(title = "药物不良事件药品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HeEventBasicUndesirable heEventBasicUndesirable)
    {
        return toAjax(heEventBasicUndesirableService.insertHeEventBasicUndesirable(heEventBasicUndesirable));
    }

    /**
     * 修改药物不良事件药品
     */
    @RequiresPermissions("project:undesirable:edit")
    @Log(title = "药物不良事件药品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HeEventBasicUndesirable heEventBasicUndesirable)
    {
        return toAjax(heEventBasicUndesirableService.updateHeEventBasicUndesirable(heEventBasicUndesirable));
    }

    /**
     * 删除药物不良事件药品
     */
    @RequiresPermissions("project:undesirable:remove")
    @Log(title = "药物不良事件药品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(heEventBasicUndesirableService.deleteHeEventBasicUndesirableByIds(ids));
    }
}
